
#include "ApplyDelegate.h"
#include <QtWidgets>

ApplyDelegate::ApplyDelegate(QObject *parent)
    : QSqlRelationalDelegate(parent)
{
}

void ApplyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const
{
    QStyleOptionViewItem opt = option;
    opt.rect.adjust(0, 0, -1, -1); // since we draw the grid ourselves
    QSqlRelationalDelegate::paint(painter, opt, index);

    QPen pen = painter->pen();
    painter->setPen(option.palette.color(QPalette::Mid));
    painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
    painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
    painter->setPen(pen);
}

QSize ApplyDelegate::sizeHint(const QStyleOptionViewItem &option,
                              const QModelIndex &index) const
{
    return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1); // since we draw the grid ourselves
}

bool ApplyDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
                                const QStyleOptionViewItem &option,
                                const QModelIndex &index)
{
    //qDebug()<<model->data(index)<<index<<endl;
    return QSqlRelationalDelegate::editorEvent(event, model, option, index);
}

